user=0
ans=0
while True:
try:
i=input()
if i[0]=='+':
user+=1
elif i[0]=='-':user-=1
else:
x=i.split(':')
ans+=len(x[1])*user
except:
break
print(ans)
/*
⠛⠛⣿⣿⣿⣿⣿⡷⢶⣦⣶⣶⣤⣤⣤⣀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀
⠀⠀⠀⠉⠉⠉⠙⠻⣿⣿⠿⠿⠛⠛⠛⠻⣿⣿⣇⠀
⠀⠀⢤⣀⣀⣀⠀⠀⢸⣷⡄⠀⣁⣀⣤⣴⣿⣿⣿⣆
⠀⠀⠀⠀⠹⠏⠀⠀⠀⣿⣧⠀⠹⣿⣿⣿⣿⣿⡿⣿
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠛⠿⠇⢀⣼⣿⣿⠛⢯⡿⡟
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠦⠴⢿⢿⣿⡿⠷⠀⣿⠀
⠀⠀⠀⠀⠀⠀⠀⠙⣷⣶⣶⣤⣤⣤⣤⣤⣶⣦⠃⠀
⠀⠀⠀⠀⠀⠀⠀⢐⣿⣾⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠈⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠻⢿⣿⣿⣿⣿⠟⠁
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define Endl endl
#define ll long long
#define in insert
#define F first
#define S second
#define py() printf("YES\n")
#define pn() printf("NO\n")
#define loop(i,n) for(int i = 0 ; i < n ; i++)
#define lop(i, x, n) for(int i = x ; i <= n ; i++)
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
int ans, cnt;
string s;
void solve(){
while(getline(cin, s)){
if(s[0] == '+') cnt++;
else if(s[0] == '-') cnt--;
else ans += cnt * (sz(s) - s.find(':') - 1);
}
printf("%d", ans);
}
int main(){
int tt = 1;
while(tt--){
solve();
}
return 0;
}
946A - Partition | 1068B - LCM |
1692E - Binary Deque | 679A - Bear and Prime 100 |
488A - Giga Tower | 14A - Letter |
1150A - Stock Arbitraging | 1552A - Subsequence Permutation |
1131F - Asya And Kittens | 1475F - Unusual Matrix |
133B - Unary | 1547A - Shortest Path with Obstacle |
624A - Save Luke | 1238A - Prime Subtraction |
1107C - Brutality | 1391B - Fix You |
988B - Substrings Sort | 312A - Whose sentence is it |
513A - Game | 1711E - XOR Triangle |
688A - Opponents | 20C - Dijkstra |
1627D - Not Adding | 893B - Beautiful Divisors |
864B - Polycarp and Letters | 1088A - Ehab and another construction problem |
1177B - Digits Sequence (Hard Edition) | 1155B - Game with Telephone Numbers |
1284A - New Year and Naming | 863B - Kayaking |